﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers {
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.models.world.vos.actors.*;
    import reprise.tweens.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.utils.*;
    import net.wooga.pets.controllers.startup.*;
    import com.robertpenner.easing.*;
    import net.wooga.pets.models.world.*;

    public class CreateRewardAnimationIntoHospitalCommand extends Command {

        public var event:InfoEvent;
        public var worldModel:WorldModel;
        public var gameViewModel:GameViewModel;
        public var popupModel:PopupModel;
        private var _iconToAnimate:MovieClip;

        override public function execute():void{
            var _local1:int;
            var _local6:Point;
            var _local7:Point;
            _local1 = 40;
            var _local2:Object = this.event.info;
            var _local3:String = _local2[EventConstants.ITEM_TYPE];
            var _local4:String = _local2[EventConstants.TARGET_ID];
            var _local5:AbstractActorVO = AbstractActorVO(this.worldModel.getActor(_local4));
            _local6 = this.getStartPosition(_local3);
            _local7 = this.getEndPosition(_local5);
            this._iconToAnimate = AssetsLibrary.getMovieClip(_local3);
            this._iconToAnimate.mouseEnabled = false;
            this._iconToAnimate.mouseChildren = false;
            this._iconToAnimate.stop();
            var _local8:Number = (_local1 / this._iconToAnimate.height);
            this._iconToAnimate.x = _local6.x;
            this._iconToAnimate.y = _local6.y;
            this._iconToAnimate.scaleX = (this._iconToAnimate.scaleY = _local8);
            contextView.stage.addChild(this._iconToAnimate);
            this._iconToAnimate.visible = !(this.popupModel.isPopupOpen());
            this._iconToAnimate.cacheAsBitmap = true;
            var _local9:SimpleTween = new SimpleTween(350);
            _local9.addTweenProperty(this._iconToAnimate, "x", this._iconToAnimate.x, _local7.x, Quad.easeOut);
            _local9.addTweenProperty(this._iconToAnimate, "y", this._iconToAnimate.y, _local7.y, Quad.easeOut);
            _local9.addTweenProperty(this._iconToAnimate, "scaleX", this._iconToAnimate.scaleX, this.gameViewModel.hospitalViewScale, Quad.easeOut);
            _local9.addTweenProperty(this._iconToAnimate, "scaleY", this._iconToAnimate.scaleY, this.gameViewModel.hospitalViewScale, Quad.easeOut);
            _local9.addEventListener(Event.COMPLETE, this.rewardAnimation_complete);
            _local9.execute();
        }
        private function getEndPosition(_arg1:AbstractActorVO):Point{
            return (new Point((_arg1.viewRectangle.x + (_arg1.viewRectangle.width / 2)), (_arg1.viewRectangle.y + (_arg1.viewRectangle.height / 2))));
        }
        private function rewardAnimation_complete(_arg1:Event):void{
            contextView.stage.removeChild(this._iconToAnimate);
            this._iconToAnimate = null;
        }
        private function getStartPosition(_arg1:String):Point{
            var _local2:Point;
            var _local3 = !((_arg1.indexOf("collection") == -1));
            if (_local3){
                _local2 = GameConstants.REWARD_MENU_POSITION_COLLECTION;
                return (_local2);
            };
            switch (_arg1){
                case GameConstants.REWARD_COFFEE:
                case GameConstants.REWARD_COFFEE_PACK:
                    _local2 = GameConstants.REWARD_MENU_POSITION_COFFEE;
                    break;
                case GameConstants.REWARD_BATTERY:
                    _local2 = GameConstants.REWARD_MENU_POSITION_BATTERY;
                    break;
                case GameConstants.REWARD_LOVE:
                    _local2 = GameConstants.REWARD_MENU_POSITION_LOVE;
                    break;
                case GameConstants.REWARD_ICE:
                    _local2 = GameConstants.REWARD_MENU_POSITION_ICE;
                    break;
                case GameConstants.REWARD_FIRE:
                    _local2 = GameConstants.REWARD_MENU_POSITION_FIRE;
                    break;
                case GameConstants.REWARD_AIR:
                    _local2 = GameConstants.REWARD_MENU_POSITION_AIR;
                    break;
                case GameConstants.REWARD_STAR:
                    _local2 = GameConstants.REWARD_MENU_POSITION_STAR;
                    break;
                case GameConstants.REWARD_WATER:
                    _local2 = GameConstants.REWARD_MENU_POSITION_WATER;
                    break;
                case GameConstants.REWARD_COIN_STACK:
                    _local2 = GameConstants.REWARD_MENU_POSITION_COINS;
                    break;
                case GameConstants.REWARD_COIN:
                    _local2 = GameConstants.REWARD_MENU_POSITION_COINS;
                    break;
                case GameConstants.REWARD_BOOST:
                    _local2 = GameConstants.REWARD_MENU_POSITION_BOOSTS;
                    break;
                case GameConstants.REWARD_XP:
                    _local2 = GameConstants.REWARD_MENU_POSITION_XP;
                    break;
                case GameConstants.REWARD_GOODS:
                    _local2 = GameConstants.REWARD_MENU_POSITION_GOODS;
                    break;
                case GameConstants.REWARD_COLOR_CONE:
                case GameConstants.REWARD_MILK_BOTTLE:
                case GameConstants.REWARD_PACIFIER:
                case GameConstants.REWARD_ROLLING_TOY:
                case GameConstants.REWARD_WOODEN_GIRAFFE:
                case GameConstants.REWARD_RICE_PUDDING:
                    _local2 = GameConstants.REWARD_MENU_POSITION_INVENTORY_TAB;
                    dispatch(new InfoEvent(EventConstants.SELECT_MENU_TAB, GameConstants.MENU_TAB_INVENTORY));
                    break;
                default:
                    log("e no target position");
                    break;
            };
            log(("itemType = " + _arg1));
            return (_local2);
        }

    }
}//package net.wooga.pets.controllers 
